package com.projec.dao.impl;

import com.projec.bean.LinkBean;
import com.projec.dao.ILinkDao;

import java.sql.*;
import java.util.List;

public class TestImpl implements ILinkDao {
    @Override
    public void add(LinkBean linkObj) {
        Connection con = null;
        PreparedStatement ps = null;
        try {
            Class.forName("com.mysql.jdbc.Driver");

            con = DriverManager.getConnection("jdbc:mysql://localhost:12345/hw?characterEncoding=utf-8",
                    "root", "lovo");
            ps = con.prepareStatement("insert into t_link(l_name,l_birthday,l_sex,l_phone)" +
                    "values (?,?,?,?)");
            ps.setObject(1, linkObj.getName());
            ps.setObject(2, linkObj.getBirthday());
            ps.setObject(3, linkObj.getSex());
            ps.setObject(4, linkObj.getPhone());

            ps.executeUpdate();

        } catch (Exception e) {
            throw new RuntimeException(e);
        }finally {
            try {
                ps.close();
                con.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }


    }

    @Override
    public void del(int id) {

    }

    @Override
    public void update(int id, String phone) {

    }

    @Override
    public List<LinkBean> findAll() {
        return null;
    }

    @Override
    public LinkBean findId(int id) {
        return null;
    }

    @Override
    public List<LinkBean> findByName(String name) {
        return null;
    }
}
